Subset construction. We have defined for a DFA L(A) = {x Σ ˆδ(q 0, x) F } and for A NFA. For any NFA A we can build a DFA A D such that L(A) = L(A D )

Similar documents
Finite Automata. Theorems - Unit I SUSAN ELIAS. Professor Department of Computer Science & Engineering Sri Venkateswara College of Engineering

Finite Automata. BİL405 - Automata Theory and Formal Languages 1

Extended transition function of a DFA

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Nondeterministic Finite Automata. Nondeterminism Subset Construction

CMPSCI 250: Introduction to Computation. Lecture #22: From λ-nfa s to NFA s to DFA s David Mix Barrington 22 April 2013

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Chap. 1.2 NonDeterministic Finite Automata (NFA)

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

Finite Automata and Regular Languages

Lecture 3: Nondeterministic Finite Automata

Introduction to Formal Languages, Automata and Computability p.1/51

Warshall s algorithm

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

Theory of Computation

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

Regular Language Equivalence and DFA Minimization. Equivalence of Two Regular Languages DFA Minimization

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Closure under the Regular Operations

Non-deterministic Finite Automata (NFAs)

Nondeterministic Finite Automata

Decision, Computation and Language

CS243, Logic and Computation Nondeterministic finite automata

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

Lecture 1: Finite State Automaton

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

More on Finite Automata and Regular Languages. (NTU EE) Regular Languages Fall / 41

Sri vidya college of engineering and technology

Nondeterministic Finite Automata

Deterministic Finite Automata (DFAs)

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

Deterministic Finite Automata (DFAs)

Chapter Five: Nondeterministic Finite Automata

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions

3515ICT: Theory of Computation. Regular languages

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Let us first give some intuitive idea about a state of a system and state transitions before describing finite automata.

CS 154, Lecture 3: DFA NFA, Regular Expressions

Finite Automata and Formal Languages TMV026/DIT321 LP Testing Equivalence of Regular Languages

Uses of finite automata

Finite Automata. Finite Automata

Chapter 6: NFA Applications

Finite Automata and Languages

CSE 105 Theory of Computation Professor Jeanne Ferrante

Before we show how languages can be proven not regular, first, how would we show a language is regular?

COM364 Automata Theory Lecture Note 2 - Nondeterminism

CSE 135: Introduction to Theory of Computation Equivalence of DFA and NFA

Formal Models in NLP

Finite Automata. Mahesh Viswanathan

Nondeterminism and Epsilon Transitions

CS 154 Formal Languages and Computability Assignment #2 Solutions

Properties of Context-Free Languages. Closure Properties Decision Properties

CS 455/555: Finite automata

Examples of Regular Expressions. Finite Automata vs. Regular Expressions. Example of Using flex. Application

Takeaway Notes: Finite State Automata

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Regular Expressions and Language Properties

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

Finite-State Machines (Automata) lecture 12

Equivalence of DFAs and NFAs

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

Deterministic Finite Automata (DFAs)

Computational Models - Lecture 1 1

Chapter 2: Finite Automata

Nondeterministic finite automata

CS 208: Automata Theory and Logic

Course 4 Finite Automata/Finite State Machines

CS 121, Section 2. Week of September 16, 2013

Closure under the Regular Operations

Computability and Complexity

Computational Models #1

Regular Expressions. Definitions Equivalence to Finite Automata

Theory of Computation

Computational Theory

Constructions on Finite Automata

Theory of Computation (I) Yijia Chen Fudan University

NPDA, CFG equivalence

Chapter 5. Finite Automata

Automata and Languages

Finite Automata and Regular Languages (part III)

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Deterministic Finite Automaton (DFA)

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Chap. 2 Finite Automata

Homomorphisms and Efficient State Minimization

Nondeterministic Finite Automata

Exam 1 CSU 390 Theory of Computation Fall 2007

Languages, regular languages, finite automata

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

UNIT-III REGULAR LANGUAGES

Nondeterminism. September 7, Nondeterminism

Advanced Automata Theory 2 Finite Automata

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

Transcription:

Search algorithm Clever algorithm even for a single word Example: find abac in abaababac See Knuth-Morris-Pratt and String searching algorithm on wikipedia

2 Subset construction We have defined for a DFA L(A) = {x Σ ˆδ(q 0, x) F } and for A NFA L(A) = {x Σ ˆδ(q 0, x) F } For any NFA A we can build a DFA A D such that L(A) = L(A D )

3 Regular languages Given an alphabet Σ, a language L Σ is regular iff there exists a DFA A such that L = L(A) Theorem: A language L is regular iff there exists a NFA N such that L = L(N) Proof: If L is regular then L = L(A) for some DFA A. To any DFA A we can associate a NFA N A such that L(A) = L(N A ). If A = (Q, Σ, δ, q 0, F) we simply take N A = (Q, Σ, δ, q 0, F) with δ (q, a) = {δ(q, a)}. Notice that δ Q Σ Pow(Q). In the other direction, if L = L(N) for some NFA N then, the power set construction gives a DFA A such that L(N) = L(A). We have then L = L(A) and so L is regular. Q.E.D.

4 Automata with -Transitions Another extension of the notion of automata that is useful but adds no more power Intuitively an -transition occurs when one can go from one state to another without reading any input symbol choc 0 5 kr stop A vending machine that may decide to stop

5 Σ = {b} Automata with -Transitions 2 3 b b b 4 5 6 -NFA accepting {b,bb,bbb} The machine can jump by itself from the state to the state 2

6 Automata with -Transitions Example: decimal numbers consisting of. An optional + or - sign 2. A string of digits 3. A decimal point, and 4. Another string of digits. Either this string, or the string (2) can be empty, but at least one of them is nonempty.

7 Automata with -Transitions A possible -NFA for this language is 0,,...,9 0,,...,9 A,+, B C 0,,...,9 D 0,,...,9 Notice the crucial use of transition to represent the optional choice of the sign + or - E

8 Automata with -Transitions Definition A -NFA consists of. a finite set of states (often denoted Q) 2. a finite set Σ of symbols (alphabet) 3. a transition function that takes as argument a state and an element of Σ {} and returns a set of states (often denoted δ); this set can be empty 4. a start state 5. a set of final or accepting states (often denoted F) We have F Q and δ Q (Σ {}) Pow(Q)

9 Automata with -Transitions For the example of decimal numbers the transition table is +,- 0,,...,9 A {B} {B} B {C} {B, E} C {D} D {D} E {D}

0 -Closures If X Q we define the -closure ECLOSE(X) inductively BASIS: If q X then q is in ECLOSE(X) INDUCTION: If p is in ECLOSE(X) and r δ(p, ) then r is in ECLOSE(X) Note that ECLOSE( ) = Informally, we follow all transitions out of X that are labeled. We say that X is -closed iff X = ECLOSE(X). Remark: X is -closed iff q X and q q implies q X

-Closures Yet another way to present ECLOSE(X) is with the two rules q X q ECLOSE(X) q ECLOSE(X) q δ(q, ) q ECLOSE(X) Intuitively q ECLOSE(X) iff there exists q 0 X and a sequence of -transitions q 0 q... qn = q

2 -Closures We say that Y Q is -closed iff If q in Y and q in δ(q, ) then q in Y We have that ECLOSE(X) is the smallest subset of Q containing X which is -closed

3 For the automaton -Closures B C F A b D a E G we have ECLOSE({A}) = {A,B,C,D,F}

4 Functional representation import List(union) data Q = A B C D E F G deriving (Eq,Show) jump :: Q -> [Q] jump A = [B,D] jump B = [C] jump C = [F] jump F = [] jump D = [] jump E = [G]

5 Functional representation issub as bs = and (map (\x -> elem x bs) as) isclos as = issub (as >>= jump) as closure qs = let qs = qs >>= jump in if issub qs qs then qs else closure (union qs qs )

6 How to run an -NFA Given any -NFA E = (Q, Σ, δ, q 0, F) we define ˆδ(q, ) = ECLOSE({q}) ˆδ(q, ay) = ˆδ(p, p (ECLOSE(q),a) y) where (X, a) = q X δ(q, a) Definition: L(E) = {x Σ ˆδ(q 0, x) F } Remark: All sets q.x = ˆδ(q, x) are -closed Remark: q.a is ECLOSE( (ECLOSE(q),a))

7 Representation in functional programming import List(union) data Q = A B C D E deriving (Eq,Show) jump :: Q -> [Q] jump A = [B] jump B = [] jump C = [] jump D = [] jump E = []

8 Representation in functional programming issub as bs = and (map (\ x -> elem x bs) as) isclos as = issub (as >>= jump) as closure qs = let qs = qs >>= jump in if issub qs qs then qs else closure (union qs qs )

9 Representation in functional programming next a A elem a "+-" = [B] next a B elem a "023456789" = [B,E] next a C elem a "023456789" = [D] next a D elem a "023456789" = [D] next. B = [C] next. E = [D] next = [] run [] q = closure [q] run (a:x) q = closure [q] >>= next a >>= run x

20 Representation in functional programming We can prove by induction on x that run x q is always -closed The main Lemma is that any union of -closed sets is a set which is -closed

2 Eliminating -Transitions We define then the DFA D = (Q D, Σ D, δ D, q D, F D ) where Q D is the set of -closed subsets of Q Σ D = Σ δ D (X, a) = ECLOSE( (X, a)) q D = ECLOSE({q 0 }) F D = {X Q D X F } Lemma: For any x Σ we have ˆδ(q 0, x) = ˆ δ D (q D, x) Theorem: L(E) = L(D) Proof: We have x L(E) iff ˆδ(q 0, x) F iff ˆδ(q 0, x) F D iff δˆ D (q D, x) F D iff x L(D). We use the Lemma to replace ˆδ(q 0, x) by δ ˆ D (q D, x)

22 Eliminating -Transitions Similar construction as for building a DFA from a NFA but now we close at each steps For the example of decimal numbers we get the following automaton 0,,...,9 0,,...,9 {A, B} +, {B} 0,,...,9 {B, E} {C, D} 0,,...,9 {C} 0,,...,9 {D} 0,,...,9 where the state is not represented Once again, we get this program mechanically!

23 Representation in functional programming pnext a qs = closure (qs >>= next a) prun [] qs = qs prun (a:x) qs = prun x (pnext a qs) run x q = prun x (closure [q])

24 NFA as labelled graphs A NFA A = (Q, Σ, δ, q 0, F) can be seen as a labelled graph a q q2 iff q 2 δ(q ) We define also, for x Σ x q q2 by induction on x If x = this means q = q 2 a If x = ay this means that there exists q Q such that q q and q y q 2 We have q x q2 iff q 2 ˆδ(q, x) L(A) = {x Σ ( q F) q 0 x q}

25 The Product Construction on NFA Given A = (Q, Σ, δ, q, F ) and A 2 = (Q 2, Σ, δ 2, q 2, F 2 ) two NFAs with the same alphabet Σ we define the product A = A A 2 as the set of state is Q Q 2 δ((r, r 2 ), a) = δ (r, a) δ 2 (r 2, a). In this way (r, r 2 ) a (s, s 2 ) iff both r a s and r 2 a s2. (r, r 2 ) is accepting iff r F and r 2 F 2 the initial state is (q, q 2 ) Lemma: (r, r 2 ) x (s, s 2 ) iff r x s and r 2 x s2 Proposition: L(A A 2 ) = L(A ) L(A 2 )

26 Be careful! Complement of a NFA In general we don t have L(A ) = Σ L(A) if A = (Q, Σ, δ, q 0, Q F) A = (Q, Σ, δ, q 0, F) and A is a NFA

27 Σ = {} Automata with -Transitions -NFA accepting all words of length multiple of 3 or 5 The automaton guesses the right direction, and then verifies that w is correct!

28 Eliminating -Transitions This corresponds to the NFA